package cn.laixueit.service.impl;

import cn.laixueit.mapper.UsersMapper;
import cn.laixueit.pojo.Users;
import cn.laixueit.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UsersMapper usersMapper;

    @Override
    public PageInfo<Users> findAll(Integer page) {
        PageHelper.startPage(page,5);
        List<Users> usersList = usersMapper.selectByExample(null);
        PageInfo<Users> pageInfo = new PageInfo<>(usersList);
        return pageInfo;
    }

    @Override
    public void save(Users users) {
        usersMapper.insertSelective(users);
    }

    @Override
    public Users findById(Integer id) {
        Users users = usersMapper.selectByPrimaryKey(id);
        return users;
    }

    @Override
    public void update(Users users) {
        usersMapper.updateByPrimaryKeySelective(users);
    }

    @Override
    public void removeById(Integer id) {
        usersMapper.deleteByPrimaryKey(id);
    }
}
